/**
 * 
 */
package com.ai.controller.system;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ai.common.controller.BaseController;
import com.ai.common.exception.AlikAssert;
import com.ai.common.model.Pagination;
import com.ai.common.model.Result;
import com.ai.mmd.system.dto.ZdinfoDTO;
import com.ai.service.system.model.ZdinfoModel;
import com.ai.service.system.service.IZdinfoService;

/**
 * 站点
 * 
 * @author Administrator
 *
 */
@RequestMapping("zd")
@Controller("com.ai.controller.system.ZDController")
public class ZDController extends BaseController {

	/**
	 * 列表
	 * @param gkinfoDTO
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("list")
	public Pagination<ZdinfoModel> list(@ModelAttribute ZdinfoDTO zdinfoDTO)
			throws Exception {
		if (zdinfoDTO.getSort()!=null) {
			zdinfoDTO.setSort(zdinfoDTO.getSort().concat(" " + zdinfoDTO.getOrder()));
		}else {
			zdinfoDTO.setSort("id desc");
		}
		return izdinfoService.getPagination(zdinfoDTO);
	}
	
	/**
	 * 编辑
	* @date 2016年6月27日 下午9:31:40
	* @param CclxInfoDTO
	* @return
	* @throws Exception
	* List<gkinfoModel>
	 */
	@ResponseBody
	@RequestMapping("neworedit")
	public Result neworedit(@ModelAttribute ZdinfoDTO zdinfoDTO,
			@RequestParam(required = true) Integer isflag)
			throws Exception {
		Result rs = new Result(true);
		ZdinfoModel zdinfoModel = new ZdinfoModel();
		switch (isflag) {
		case 0:
			//新增
			AlikAssert.isNotNull(zdinfoDTO.getZdmc(), "参数异常.");
			zdinfoDTO.setCjsj(new Date());			
			BeanUtils.copyProperties(zdinfoDTO, zdinfoModel);
			izdinfoService.insert(zdinfoModel);
			break;
		case 1:
			//编辑
			AlikAssert.isNotNull(zdinfoDTO.getId(), "参数异常.");
			zdinfoDTO.setGxsj(new Date());
			BeanUtils.copyProperties(zdinfoDTO, zdinfoModel);
			izdinfoService.updateByPrimaryKey(zdinfoModel);
			break;
		case 2:
			//删除
			AlikAssert.isNotNull(zdinfoDTO.getId(), "参数异常.");
			zdinfoDTO.setSfsc(1);
			zdinfoDTO.setGxsj(new Date());
			BeanUtils.copyProperties(zdinfoDTO, zdinfoModel);
			izdinfoService.updateByPrimaryKey(zdinfoModel);
			break;
		default:
			break;
		}
				
		return rs;
	}
	
	/**
     * 跳转
     * @return
     * @throws Exception
     */
    @RequestMapping("forward")
    public String forward() throws Exception{
        return "system/zd/list";
    }

	@Resource(name = "izdinfoService")
	private IZdinfoService izdinfoService;

}
